<template>
	<view class="customer-record full box relative flex-col bg-primary">
		<view class="header-wrap">
			<view class="header-item">
				<view class="search-wrap">
					<u-icon name="search" size="30rpx" color="#8D8D8D"></u-icon>
					<input v-model="queryKey" class="search-input" placeholder="关键词" @confirm="handleSearch" />
				</view>
				<view class="search-wrap active">
					<u-icon name="search" size="30rpx" color="#8D8D8D"></u-icon>
					<input v-model="bianma" class="search-input" placeholder="物联网编号" @confirm="handleSearch" />
				</view>
				<view class="list-count">
					<text>共{{ total }}条</text>
				</view>
			</view>
			<view class="header-item active">
				<view class="search-wrap" @click="handleChooseStatus">
					<u-icon name="arrow-down" size="30rpx" color="#8D8D8D"></u-icon>
					<text class="status-picker"
						:class="[status !== '' ? 'active' : '']">{{ statusTextEnum[status] || "设备状态"}}</text>
				</view>
				<view class="search-btn" @click="handleSearch">
					<text>搜索</text>
				</view>
			</view>

		</view>
		<view class="w-wrap">
			<view class="w-inner">
				<mescroll-uni @init="mescrollInit" :fixed="false" @down="downCallback" @up="upCallback">
					<view class="record-list">
						<view class="record-item" v-for="(item,index) in list" :key="index">
							<view class="item-name">
								<text>档案号：{{ item.dangan_no }}</text>
							</view>
							<!-- <view class="desc-wrap">
								<text class="desc-item">创建时间：</text>
							</view> -->
							<view class="date-item">
								<text>创建时间：{{ item.create_time }}</text>
							</view>
							<view class="date-item">
								<text>联系人：{{ item.name }}({{ item.mobile }})</text>
							</view>
							<view class="date-item">
								<text>所在地区：{{ item.address }}</text>
							</view>
							<view class="device-wrap">
								<image :src="item.image" mode="aspectFill" class="device-img"></image>
								<view class="device-info">
									<text class="info-text">设备型号：{{ item.xinghao }}</text>
									<text class="info-text">当前套餐：{{ item.recharge_config_name }}</text>
									<text class="info-text">设备编号：{{ item.bianma }}</text>
								</view>
								<view class="water-count">
									<text class="count-value">{{ item.shengyu_rongliang }}</text>
									<text class="count-label">剩余水量</text>
								</view>
							</view>
						</view>
					</view>
				</mescroll-uni>
			</view>
		</view>
	</view>
</template>

<script>
	import { request } from "@/utils/tool.js";
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				queryKey: "",
				bianma: "",
				date: "",
				list: [],
				status: "",
				total: ""
			}
		},
		computed: {
			statusTextEnum() {
				return { "-1": "已过期", "0": "离线", "1": "正常" }
			}
		},
		methods: {
			handleChooseStatus() {
				uni.showActionSheet({
					itemList: ["已过期", "离线", "正常", "全部"],
					success: ev => {
						const index = ev.tapIndex
						const statusEnum = { 0: -1, 1: 0, 2: 1, 3: '' }
						this.status = statusEnum[index]
						console.log(this.status, 'status');
					}
				})
			},
			handleSearch() {
				this.mescroll.triggerDownScroll()
			},
			async upCallback(ev) {
				const { num, size } = ev
				const { queryKey, status, bianma } = this
				const resp = await request({
					url: "/kehudangan/lists",
					data: {
						page_no: num,
						page_size: size,
						keyword: queryKey,
						status,
						bianma
					},
					method: "GET",
				})
				const { lists, count } = resp.data
				if (num === 1) this.list = []
				this.list.push(...lists)
				console.log(lists, 'lisats');
				this.total = count
				this.mescroll.endBySize(lists.length, count)
			}
		},
	}
</script>

<style lang="scss" scoped>
	.customer-record {
		.record-list {
			padding: 24rpx 18rpx 0;
			box-sizing: border-box;
			position: relative;

			.record-item {
				padding: 20rpx 34rpx;
				background: #FFFFFF;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				margin-bottom: 24rpx;

				.device-wrap {
					margin-top: 4rpx;
					padding: 16rpx 24rpx;
					background: #F5F3F3;
					display: flex;
					align-items: center;

					.water-count {
						padding-left: 22rpx;
						display: flex;
						flex-flow: column;
						align-items: center;
						border-left: 2rpx solid #9C9C9C;
						padding-top: 10rpx;
						padding-bottom: 10rpx;

						.count-value {
							font-weight: bold;
							font-size: 24rpx;
							color: #FF5252;
						}

						.count-label {
							font-weight: 400;
							font-size: 22rpx;
							color: #606060;
							margin-top: 18rpx;
						}
					}

					.device-info {
						margin-left: 18rpx;
						display: flex;
						flex-flow: column;
						flex: 1;

						.info-text {
							font-size: 24rpx;
							color: #515151;
							line-height: 44rpx;
						}
					}

					.device-img {
						width: 83rpx;
						height: 92rpx;
					}
				}

				&:last-child {
					margin-bottom: 0;
				}

				.item-countder {
					margin-top: 10rpx;
					padding: 12rpx 28rpx 28rpx;
					background: #F5F3F3;
					border-radius: 16rpx 16rpx 16rpx 16rpx;


					.count-line {
						display: flex;
						flex-flow: row nowrap;
						align-items: center;

						&:last-child {
							margin-top: 24rpx;
						}

						&.active {
							.count-item {
								--first-circle-color: #2AB7AC;

								&:last-child {
									--first-circle-color: #45AE56;
								}

								.item-value {
									color: #D26B40;
								}
							}
						}

						.count-item {
							flex: 1;
							display: flex;
							flex-flow: column;
							align-items: center;
							--first-circle-color: #623BA9;

							&:last-child {
								--first-circle-color: #D84D46;
							}

							.item-label {
								font-size: 24rpx;
								color: #77797A;
								line-height: 44rpx;
								position: relative;


								&::before {
									content: "";
									display: block;
									position: absolute;
									width: 12rpx;
									height: 12rpx;
									background: var(--first-circle-color);
									border-radius: 50%;
									left: -20rpx;
									top: 50%;
									transform: translateY(-50%);
								}
							}

							.item-value {
								font-weight: bold;
								font-size: 32rpx;
								color: #2F3132;
								margin-top: 12rpx;
							}
						}
					}

					.count-date {
						font-weight: bold;
						font-size: 26rpx;
						color: #000000;
						line-height: 44rpx;
						margin-bottom: 10rpx;
					}
				}

				.date-item {
					font-size: 28rpx;
					color: #515151;
					line-height: 44rpx;
				}

				.desc-wrap {
					font-size: 28rpx;
					color: #515151;
					line-height: 44rpx;

					.desc-item:first-child {
						padding-right: 114rpx;
					}
				}

				.item-name {
					font-size: 28rpx;
					color: #515151;
					line-height: 44rpx;
				}
			}
		}

		.header-wrap {
			padding: 10rpx;
			box-sizing: border-box;
			background-color: #fff;

			.header-item {
				position: relative;
				display: flex;
				align-items: center;

				.list-count {
					font-weight: 400;
					font-size: 28rpx;
					color: #FF0000;
					line-height: 44rpx;
					margin-left: auto;
				}

				&.active {
					margin-top: 18rpx;
				}
			}

			.search-btn {
				width: 116rpx;
				height: 64rpx;
				background: #3361F0;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				margin-left: auto;
				line-height: 64rpx;
				font-size: 26rpx;
				color: #FFFFFF;
				text-align: center;
			}

			.data-wrap {
				margin-left: 18rpx;
				padding: 8rpx 20rpx 8rpx 20rpx;
				display: flex;
				align-items: center;
				background: #F4F4F4;
				border-radius: 30rpx 30rpx 30rpx 30rpx;

				.date-value {
					font-size: 26rpx;
					color: #8D8D8D;
					line-height: 44rpx;
					margin-right: 10rpx;
				}
			}

			.search-wrap {
				display: flex;
				align-items: center;
				padding: 8rpx 18rpx;
				box-sizing: border-box;
				position: relative;
				background: #F4F4F4;
				border-radius: 30rpx 30rpx 30rpx 30rpx;
				width: 296rpx;

				.status-picker {
					font-size: 26rpx;
					color: #8D8D8D;
					line-height: 44rpx;
					margin-left: 8rpx;

					&.active {
						color: #333;
					}
				}

				&.active {
					margin-left: 12rpx;
				}

				.search-input {
					margin-left: 8rpx;
					height: 44rpx;
					font-size: 26rpx;
					color: #333;
					line-height: 44rpx;
					flex: 1;
				}
			}
		}
	}
</style>